<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>第&nbsp;11&nbsp;章.Gradle命令行的基本使用</title>
<link xmlns:xslthl="http://xslthl.sf.net" type="text/css"
	rel="stylesheet" href="../css/base.css">
<link xmlns:xslthl="http://xslthl.sf.net" type="text/css"
	rel="stylesheet" href="../css/docs.css">
<link xmlns:xslthl="http://xslthl.sf.net" type="text/css"
	rel="stylesheet" href="../css/userguide.css">
<meta content="DocBook XSL Stylesheets V1.75.2" name="generator">
<link rel="home" href="userguide.html" title="Gradle User Guide">
<link rel="up" href="userguide.html" title="Gradle User Guide">
<link rel="prev" href="../ch10/web_project_tutorial.html"
	title="Chapter&nbsp;10.&nbsp;Web Application Quickstart">
<link rel="next" href="../tutorial_gradle_gui.html"
	title="Chapter&nbsp;12.&nbsp;Using the Gradle Graphical User Interface">
</head>
<body>
	<div class="navheader">
		<div>
			<div class="navbar">
				<a xmlns:xslthl="http://xslthl.sf.net"
					href="../ch10/web_project_tutorial.html"
					title=">第&nbsp;10&nbsp;章.Web构建入门">上一页</a><span>|</span><a
					xmlns:xslthl="http://xslthl.sf.net" href="../userguide.html"
					title="Gradle User Guide">返回目录</a><span>|</span><a
					xmlns:xslthl="http://xslthl.sf.net" href="../tutorial_gradle_gui.html"
					title=">第&nbsp;12&nbsp;章.Gradle GUI">下一页</a>
			</div>
		</div>
	</div>
	<div class="chapter">
		<div class="titlepage">
			<div>
				<div>
					<h1 xmlns:xslthl="http://xslthl.sf.net">
						<a name="tutorial_gradle_command_line"></a>第&nbsp;11&nbsp;章.Gradle命令行的基本使用
					</h1>
					<h3 xmlns:xslthl="http://xslthl.sf.net">
                        <a name="tutorial_gradle_command_line"></a>Chapter&nbsp;11.&nbsp;Using
                        the Gradle Command-Line
                    </h3>
				</div>
			</div>
		</div>
		<p>
		  本章介绍了命令行的基本使用.正如在前面的章节里你所见到的调用 <span class="command"><strong>gradle</strong></span>命令来完成一些功能<br>
			This chapter introduces the basics of the Gradle command-line. You
			run a build using the <span class="command"><strong>gradle</strong></span>
			command, which you have already seen in action in previous chapters.
		</p>
		<div class="section">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title">
							<a name="N1077C"></a>11.1.&nbsp;多任务调用
						</h2>
						<h4 class="title">
                            <a name="N1077C"></a>11.1.&nbsp;Executing multiple tasks
                        </h4>
					</div>
				</div>
			</div>
			<p>
			     你可以以列表的形式在命令行中一次调用多个任务.例如 <strong
                    class="userinput"><code>gradle compile test</code></strong>命令会依次调用,并且每个任务仅会被调用一次.
                    <code class="literal">compile</code>和<code class="literal">test</code>任务以及它们的依赖任务.
                    无论它们是否被包含在脚本中:即无论是以命令行的形式定义的任务还是依赖于其它任务都会被调用执行.来看下面的例子.<br>
				You can execute multiple tasks in a single build by listing each of
				the tasks on the command-line. For example, the command <strong
					class="userinput"><code>gradle compile test</code></strong> will
				execute the
				<code class="literal">compile</code>
				and
				<code class="literal">test</code>
				tasks. Gradle will execute the tasks in the order that they are
				listed on the command-line, and will also execute the dependencies
				for each task. Each task is executed once only, regardless of how it
				came to be included in the build: whether it was specified on the
				command-line, or it a dependency of another task, or both. Let's
				look at an example.
			</p>
			<p>
			 下面定义了四个任务.<code class="literal">dist</code>和<code class="literal">test</code>
                             都 依赖于<code class="literal">compile</code>,只用当 <code class="literal">compile</code>被调用之后才会调用<strong class="userinput"><code>gradle
                        dist test</code></strong>任务<br>
				Below four tasks are defined. Both
				<code class="literal">dist</code>
				and
				<code class="literal">test</code>
				depend on the
				<code class="literal">compile</code>
				task. Running <strong class="userinput"><code>gradle
						dist test</code></strong> for this build script results in the
				<code class="literal">compile</code>
				task being executed only once.
			</p>
			<div class="figure">
				<a name="N1079B"></a>
				<p class="title">
					<b>
					示例图&nbsp;11.1.&nbsp;任务依赖<br>
					Figure&nbsp;11.1.&nbsp;Task dependencies</b>
				</p>
				<div class="figure-contents">
					<img src="../img/commandLineTutorialTasks.png" alt="Task dependencies">
				</div>
			</div>
			<br class="figure-break">
			<div class="example">
				<a name="multipleTasksFromCommandLine"></a>
				<p class="title">
					<b>
					例&nbsp;11.1.&nbsp;多任务调用<br>
					Example&nbsp;11.1.&nbsp;Executing multiple tasks</b>
				</p>
				<div class="example-contents">
					<p>
						<code class="filename">build.gradle</code>
					</p>
					<pre class="programlisting">task compile &lt;&lt; {
    println <span xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'compiling source'</span>
}

task compileTest(dependsOn: compile) &lt;&lt; {
    println <span xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'compiling unit tests'</span>
}

task test(dependsOn: [compile, compileTest]) &lt;&lt; {
    println <span xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'running unit tests'</span>
}

task dist(dependsOn: [compile, test]) &lt;&lt; {
    println <span xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'building the distribution'</span>
}</pre>
					<p><strong class="userinput"><code>gradle
                                dist test</code></strong>的输出结果.<br>
						Output of <strong class="userinput"><code>gradle
								dist test</code></strong>
					</p>
					<pre class="screen">&gt; gradle dist test
:compile
compiling source
:compileTest
compiling unit tests
:test
running unit tests
:dist
building the distribution

BUILD SUCCESSFUL

Total time: 1 secs</pre>
				</div>
			</div>
			<br class="example-break">
			<p>
                由于每个任务仅会被调用一次,所以调用<strong
                    class="userinput"><code>gradle test test</code></strong>与调用<strong class="userinput"><code>gradle
                        test</code></strong>效果是相同的.<br>			
				Because each task is executed once only, executing <strong
					class="userinput"><code>gradle test test</code></strong> is exactly
				the same as executing <strong class="userinput"><code>gradle
						test</code></strong>.
			</p>
		</div>
		<div class="section">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title">
							<a name="sec:excluding_tasks_from_the_command_line"></a>11.2.&nbsp;排除任务
						</h2>
						<h4 class="title">
                            <a name="sec:excluding_tasks_from_the_command_line"></a>11.2.&nbsp;Excluding
                            tasks
                        </h4>
					</div>
				</div>
			</div>
			<p>
			     你可以用命令行选项<code class="option">-x</code>来排除某些任务,让我们用上面的例子来示范一下.<br>
				You can exclude a task from being executed using the
				<code class="option">-x</code>
				command-line option and providing the name of the task to exclude.
				Let's try this with the sample build file above.
			</p>
			<div class="example">
				<a name="excludeTask"></a>
				<p class="title">
					<b>
					例&nbsp;11.2.&nbsp;排除任务.<br>
					Example&nbsp;11.2.&nbsp;Excluding tasks</b>
				</p>
				<div class="example-contents">
					<p>
					<strong class="userinput"><code>gradle
                                dist -x test</code></strong>的输出结果.<br>
						Output of <strong class="userinput"><code>gradle
								dist -x test</code></strong>
					</p>
					<pre class="screen">&gt; gradle dist -x test
:compile
compiling source
:dist
building the distribution

BUILD SUCCESSFUL

Total time: 1 secs</pre>
				</div>
			</div>
			<br class="example-break">
			<p>
			可以看到,<code class="literal">test</code>任务并没有被调用,即使他是<code class="literal">dist</code>任务的依赖.
			同时<code class="literal">test</code>任务的依赖任务<code class="literal">compileTest</code>也没有被调用,而像
			<code class="literal">compile</code>被<code class="literal">test</code>和其它任务同时依赖的任务仍然会被调用.<br>
				You can see from the output of this example, that the
				<code class="literal">test</code>
				task is not executed, even though it is a dependency of the
				<code class="literal">dist</code>
				task. You will also notice that the
				<code class="literal">test</code>
				task's dependencies, such as
				<code class="literal">compileTest</code>
				are not executed either. Those dependencies of
				<code class="literal">test</code>
				that are required by another task, such as
				<code class="literal">compile</code>
				, are still executed.
			</p>
		</div>
		<div class="section">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title">
							<a name="sec:continue_build_on_failure"></a>11.3.&nbsp;失败后继续执行 
						</h2>
						  <h4 class="title">
                            <a name="sec:continue_build_on_failure"></a>11.3.&nbsp;Continuing
                            the build when a failure occurs
                        </h4>
					</div>
				</div>
			</div>
			<p>
			    默认情况下只要有任务调用失败Gradle就是中断执行.这可能会使调用过程更快,但那些后面隐藏的错误不会被发现.
			    所以你可以使用<code class="literal">--continue</code>在一次调用中尽可能多的发现所有问题.<br>
				By default, Gradle will abort execution and fail the build as soon
				as any task fails. This allows the build to complete sooner, but
				hides other failures that would have occurred. In order to discover
				as many failures as possible in a single build execution, you can
				use the
				<code class="literal">--continue</code>
				option.
			</p>
			<p>
			    采用了<code class="literal">--continue</code>选项,Gralde会调用<span class="emphasis"><em>每一个</em></span>任务以及它们依赖的任务.
			    而不是一旦出现错误就会中断执行.所有错误信息都会在最后被列出来.<br>
				When executed with
				<code class="literal">--continue</code>
				, Gradle will execute <span class="emphasis"><em>every</em></span>
				task to be executed where all of the dependencies for that task
				completed without failure, instead of stopping as soon as the first
				failure is encountered. Each of the encountered failures will be
				reported at the end of the build.
			</p>
			<p>
			一旦某个任务执行失败,那么所有依赖于该任务的子任务都不会被调用.例如由于test任务依赖于complie任务,所以如果compile调用出错,test便不会被直接或间接调用.<br>
			If a task fails, any subsequent tasks that were depending on
				it will not be executed, as it is not safe to do so. For example,
				tests will not run if there is a compilation failure in the code
				under test; because the test task will depend on the compilation
				task (either directly or indirectly).</p>
		</div>
		<div class="section">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title">
							<a name="N107F3"></a>11.4.&nbsp;简化任务名
						</h2>
						<h4 class="title">
                            <a name="N107F3"></a>11.4.&nbsp;Task name abbreviation
                        </h4>
					</div>
				</div>
			</div>
			<p>
				当你试图调用某个任务的时候,无需输入任务的全名.只需提供足够的可以唯一区分出该任务的字符即可.例如,上面的例子你也可以这么写.
				用<strong class="userinput"><code>gradle di</code></strong>来直接调用<code class="literal">dist</code>任务<br>
				When you specify tasks on the command-line, you don't have to
				provide the full name of the task. You only need to provide enough
				of the task name to uniquely identify the task. For example, in the
				sample build above, you can execute task
				<code class="literal">dist</code>
				by running <strong class="userinput"><code>gradle di</code></strong>:
			</p>
			<div class="example">
				<a name="abbreviateTaskName"></a>
				<p class="title">
					<b>
					例&nbsp;11.3.&nbsp;简化任务名<br>
					Example&nbsp;11.3.&nbsp;Abbreviated task name</b>
				</p>
				<div class="example-contents">
					<p>
					<strong class="userinput"><code>gradle
                                di</code></strong>的输出结果<br>
						Output of <strong class="userinput"><code>gradle
								di</code></strong>
					</p>
					<pre class="screen">&gt; gradle di
:compile
compiling source
:compileTest
compiling unit tests
:test
running unit tests
:dist
building the distribution

BUILD SUCCESSFUL

Total time: 1 secs</pre>
				</div>
			</div>
			<br class="example-break">
			<p>
			     你也可以用驼峰命名的任务中每个单词的首字母进行调用.例如,可以执行<strong class="userinput"><code>gradle
                        compTest</code></strong> or even <strong class="userinput"><code>gradle
                        cT</code></strong>来调用   <code class="literal">compileTest</code>任务<br>
				You can also abbreviate each word in a camel case task name. For
				example, you can execute task
				<code class="literal">compileTest</code>
				by running <strong class="userinput"><code>gradle
						compTest</code></strong> or even <strong class="userinput"><code>gradle
						cT</code></strong>
			</p>
			<div class="example">
				<a name="abbreviateCamelCaseTaskName"></a>
				<p class="title">
					<b>
					例&nbsp;11.4.&nbsp;简化驼峰任务名<br>
					Example&nbsp;11.4.&nbsp;Abbreviated camel case task name</b>
				</p>
				<div class="example-contents">
					<p>
					 <strong class="userinput"><code>gradle
                                cT</code></strong>的输出结果.<br>
						Output of <strong class="userinput"><code>gradle
								cT</code></strong>
					</p>
					<pre class="screen">&gt; gradle cT
:compile
compiling source
:compileTest
compiling unit tests

BUILD SUCCESSFUL

Total time: 1 secs</pre>
				</div>
			</div>
			<br class="example-break">
			<p>
			    简化后你仍然可以使用<code class="option">-x</code>参数.<br>
				You can also use these abbreviations with the
				<code class="option">-x</code>
				command-line option.
			</p>
		</div>
		<div class="section">
			<div class="titlepage">
				<div>
					<div>
					   <h2 class="title">
                            <a name="sec:selecting_build"></a>11.5.&nbsp;选择构建位置
                        </h2>
						<h4 class="title">
							<a name="sec:selecting_build"></a>11.5.&nbsp;Selecting which
							build to execute
						</h4>
					</div>
				</div>
			</div>
			<p>
			    调用<span class="command"><strong>gradle</strong></span>时,默认情况下总是会构建当前目录下的文件,
			    可以使用<code class="option">-b</code>参数选择构建的文件,并且当你使用此参数时<code class="filename">settings.gradle</code>将不会生效,看下面的例子:<br>
				When you run the <span class="command"><strong>gradle</strong></span>
				command, it looks for a build file in the current directory. You can
				use the
				<code class="option">-b</code>
				option to select another build file. If you use
				<code class="option">-b</code>
				option then
				<code class="filename">settings.gradle</code>
				file is not used. Example:
			</p>
			<div class="example">
				<a name="selectProjectUsingBuildFile"></a>
				<p class="title">
					<b>
					例&nbsp;11.5.&nbsp;选择文件构建<br>
					Example&nbsp;11.5.&nbsp;Selecting the project using a build
						file</b>
				</p>
				<div class="example-contents">
					<p>
						<code class="filename">subdir/myproject.gradle</code>
					</p>
					<pre class="programlisting">task hello &lt;&lt; {
    println <span xmlns:xslthl="http://xslthl.sf.net" class="hl-string">"using build file '$buildFile.name' in '$buildFile.parentFile.name'."</span>
}</pre>
					<p>
					<strong class="userinput"><code>gradle
                                -q -b subdir/myproject.gradle hello</code></strong>的输出结果<br>
						Output of <strong class="userinput"><code>gradle
								-q -b subdir/myproject.gradle hello</code></strong>
					</p>
					<pre class="screen">&gt; gradle -q -b subdir/myproject.gradle hello
using build file 'myproject.gradle' in 'subdir'.</pre>
				</div>
			</div>
			<br class="example-break">
			<p>
			    另外,你可以使用<code class="option">-p</code>参数来指定构建的目录,例如在多项目构建中你可以用<code class="option">-p</code>来替代<code class="option">-b</code>参数<br>
				Alternatively, you can use the
				<code class="option">-p</code>
				option to specify the project directory to use. For multi-project
				builds you should use
				<code class="option">-p</code>
				option instead of
				<code class="option">-b</code>
				option.
			</p>
			<div class="example">
				<a name="selectProjectUsingProjectDir"></a>
				<p class="title">
					<b>
					例&nbsp;11.6.&nbsp;选择构建目录<br>
					Example&nbsp;11.6.&nbsp;Selecting the project using project
						directory</b>
				</p>
				<div class="example-contents">
					<p>
					<strong class="userinput"><code>gradle
                                -q -p subdir hello</code></strong>的输出结果<br>
						Output of <strong class="userinput"><code>gradle
								-q -p subdir hello</code></strong>
					</p>
					<pre class="screen">&gt; gradle -q -p subdir hello
using build file 'build.gradle' in 'subdir'.</pre>
				</div>
			</div>
			<div class="exampleLocation">
                        <p>
                        <span class="emphasis"><em>备注:</em></span> -b参数用以指定脚本具体所在位置,格式为 dirpwd/build.gradle.-p参数用以指定脚本目录即可.
                        </p>
                    </div>
			<br class="example-break">
		</div>
		<div class="section">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title">
							<a name="sec:obtaining_information_about_your_build"></a>11.6.&nbsp;获取构建信息
						</h2>
						<h4 class="title">
                            <a name="sec:obtaining_information_about_your_build"></a>11.6.&nbsp;Obtaining
                            information about your build
                        </h4>
					</div>
				</div>
			</div>
			<p>
			Gradle提供了许多内置任务来收集构建信息.这些内置任务对于了解依赖结构以及解决问题都是很有帮助的.<br>
			Gradle provides several built-in tasks which show particular
				details of your build. This can be useful for understanding the
				structure and dependencies of your build, and for debugging
				problems.</p>
			<p>
			    了解更多,可以参阅<a class="link" href="project_reports_plugin.html">项目报告插件</a>以为你的项目添加构建报告.<br>
				In addition to the built-in tasks shown below, you can also use the
				<a class="link" href="project_reports_plugin.html">project
					report plugin</a> to add tasks to your project which will generate
				these reports.
			</p>
			<div class="section">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title">
								<a name="N10864"></a>11.6.1.&nbsp;项目列表
							</h3>
							<h5 class="title">
                                <a name="N10864"></a>11.6.1.&nbsp;Listing projects
                            </h5>
						</div>
					</div>
				</div>
				执行<strong class="userinput"><code>gradle projects</code></strong>会为你列出子项目名称列表.如下例.<br> 
				<p>
					Running <strong class="userinput"><code>gradle
							projects</code></strong> gives you a list of the sub-projects of the selected
					project, displayed in a hierarchy. Here is an example:
				</p>
				<div class="example">
					<a name="projectListReport"></a>
					<p class="title">
						<b>
						例&nbsp;11.7.&nbsp;收集项目信息<br>
						Example&nbsp;11.7.&nbsp;Obtaining information about
							projects</b>
					</p>
					<div class="example-contents">
						<p>
						<strong class="userinput"><code>gradle
                                    -q projects</code></strong>的输出结果<br>
							Output of <strong class="userinput"><code>gradle
									-q projects</code></strong>
						</p>
						<pre class="screen">&gt; gradle -q projects
------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'projectReports'
+--- Project ':api' - The shared API for the application
\--- Project ':webapp' - The Web application implementation

To see a list of the tasks of a project, run gradle &lt;project-path&gt;:tasks
For example, try running gradle :api:tasks</pre>
					</div>
				</div>
				<br class="example-break">
				<p>
				    这份报告展示了每个项目的描述信息.当然你可以在项目中用<code class="literal">description</code>属性来指定这些描述信息.<br>
					The report shows the description of each project, if specified. You
					can provide a description for a project by setting the
					<code class="literal">description</code>
					property:
				</p>
				<div class="example">
					<a name="projectListReport"></a>
					<p class="title">
						<b>
						例&nbsp;11.8.&nbsp;为项目添加描述信息.<br>
						Example&nbsp;11.8.&nbsp;Providing a description for a
							project</b>
					</p>
					<div class="example-contents">
						<p>
							<code class="filename">build.gradle</code>
						</p>
						<pre class="programlisting">description = <span
								xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'The shared API for the application'</span>
						</pre>
					</div>
				</div>
				<br class="example-break">
			</div>
			<div class="section">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title">
								<a name="sec:listing_tasks"></a>11.6.2.&nbsp;任务列表
							</h3>
							<h5 class="title">
                                <a name="sec:listing_tasks"></a>11.6.2.&nbsp;Listing tasks
                            </h5>
						</div>
					</div>
				</div>
				<p>
				 执行<strong class="userinput"><code>gradle tasks</code></strong>会列出项目中所有任务.
				 这会显示项目中所有的默认任务以及每个任务的描述.如下例<br>
					Running <strong class="userinput"><code>gradle
							tasks</code></strong> gives you a list of the main tasks of the selected project.
					This report shows the default tasks for the project, if any, and a
					description for each task. Below is an example of this report:
				</p>
				<div class="example">
					<a name="taskListReport"></a>
					<p class="title">
						<b>
						例&nbsp;11.9.&nbsp;获取任务信息<br>
						Example&nbsp;11.9.&nbsp;Obtaining information about tasks</b>
					</p>
					<div class="example-contents">
						<p>
							Output of <strong class="userinput"><code>gradle
									-q tasks</code></strong>
						</p>
						<pre class="screen">&gt; gradle -q tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Default tasks: dists

Build tasks
-----------
clean - Deletes the build directory (build)
dists - Builds the distribution
libs - Builds the JAR

Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]

Help tasks
----------
dependencies - Displays all dependencies declared in root project 'projectReports'.
dependencyInsight - Displays the insight into a specific dependency in root project 'projectReports'.
help - Displays a help message
projects - Displays the sub-projects of root project 'projectReports'.
properties - Displays the properties of root project 'projectReports'.
tasks - Displays the tasks runnable from root project 'projectReports' (some of the displayed tasks may belong to subprojects).

To see all tasks and more detail, run with --all.</pre>
					</div>
				</div>
				<br class="example-break">
				<p>
				默认情况下,这只会显示那些被分组的任务.你可以通过为任务设置<code class="literal">group</code>属性和<code class="literal">description</code>来把
				这些信息展示到结果中.<br>
					By default, this report shows only those tasks which have been
					assigned to a task group. You can do this by setting the
					<code class="literal">group</code>
					property for the task. You can also set the
					<code class="literal">description</code>
					property, to provide a description to be included in the report.
				</p>
				<div class="example">
					<a name="taskListReport"></a>
					<p class="title">
						<b>
						例&nbsp;11.10.&nbsp;更改任务报告内容<br>
						Example&nbsp;11.10.&nbsp;Changing the content of the task
							report</b>
					</p>
					<div class="example-contents">
						<p>
							<code class="filename">build.gradle</code>
						</p>
						<pre class="programlisting">dists {
    description = <span xmlns:xslthl="http://xslthl.sf.net"
								class="hl-string">'Builds the distribution'</span>
    group = <span xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'build'</span>
}</pre>
					</div>
				</div>
				<br class="example-break">
				<p>
				    当然你也可以用<code class="option">--all</code>参数来收集更多任务信息.这会列出项目中所有任务以及任务之间的依赖关系.<br>
					You can obtain more information in the task listing using the
					<code class="option">--all</code>
					option. With this option, the task report lists all tasks in the
					project, grouped by main task, and the dependencies for each task.
					Here is an example:
				</p>
				<div class="example">
					<a name="taskListAllReport"></a>
					<p class="title">
						<b>Example&nbsp;11.11.&nbsp;Obtaining more information about
							tasks</b>
					</p>
					<div class="example-contents">
						<p>
							Output of <strong class="userinput"><code>gradle
									-q tasks --all</code></strong>
						</p>
						<pre class="screen">&gt; gradle -q tasks --all
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Default tasks: dists

Build tasks
-----------
clean - Deletes the build directory (build)
api:clean - Deletes the build directory (build)
webapp:clean - Deletes the build directory (build)
dists - Builds the distribution [api:libs, webapp:libs]
    docs - Builds the documentation
api:libs - Builds the JAR
    api:compile - Compiles the source files
webapp:libs - Builds the JAR [api:libs]
    webapp:compile - Compiles the source files

Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]

Help tasks
----------
dependencies - Displays all dependencies declared in root project 'projectReports'.
api:dependencies - Displays all dependencies declared in project ':api'.
webapp:dependencies - Displays all dependencies declared in project ':webapp'.
dependencyInsight - Displays the insight into a specific dependency in root project 'projectReports'.
api:dependencyInsight - Displays the insight into a specific dependency in project ':api'.
webapp:dependencyInsight - Displays the insight into a specific dependency in project ':webapp'.
help - Displays a help message
api:help - Displays a help message
webapp:help - Displays a help message
projects - Displays the sub-projects of root project 'projectReports'.
api:projects - Displays the sub-projects of project ':api'.
webapp:projects - Displays the sub-projects of project ':webapp'.
properties - Displays the properties of root project 'projectReports'.
api:properties - Displays the properties of project ':api'.
webapp:properties - Displays the properties of project ':webapp'.
tasks - Displays the tasks runnable from root project 'projectReports' (some of the displayed tasks may belong to subprojects).
api:tasks - Displays the tasks runnable from project ':api'.
webapp:tasks - Displays the tasks runnable from project ':webapp'.</pre>
					</div>
				</div>
				<br class="example-break">
			</div>
			<div class="section">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title">
								<a name="sec:show_task_details"></a>11.6.3.&nbsp;获取任务帮助信息
							</h3>
							<h5 class="title">
                                <a name="sec:show_task_details"></a>11.6.3.&nbsp;Show task usage
                                details
                            </h5>
						</div>
					</div>
				</div>
				<p>
				执行<strong class="userinput"><code>gradle help --task someTask</code></strong>可以显示指定任务的详细信息.
				或者多项目构建中相同任务名称的所有任务的信息.如下例.<br> 
					Running <strong class="userinput"><code>gradle help
							--task someTask</code></strong> gives you detailed information about a specific
					task or multiple tasks matching the given task name in your
					multiproject build. Below is an example of this detailed
					information:
				</p>
				<div class="example">
					<a name="taskHelp"></a>
					<p class="title">
						<b>
						例&nbsp;11.12.&nbsp;获取任务帮助<br>
						Example&nbsp;11.12.&nbsp;Obtaining detailed help for tasks</b>
					</p>
					<div class="example-contents">
						<p>
						<strong class="userinput"><code>gradle
                                    -q help --task libs</code></strong>的输出结果<br>
							Output of <strong class="userinput"><code>gradle
									-q help --task libs</code></strong>
						</p>
						<pre class="screen">&gt; gradle -q help --task libs
Detailed task information for libs

Paths
     :api:libs
     :webapp:libs

Type
     Task (org.gradle.api.Task)

Description
     Builds the JAR</pre>
					</div>
				</div>
				<br class="example-break">
				<p>
				这些结果包含了任务的路径、类型以及描述信息等.<br>
				This information includes the full task path, the task type,
					possible commandline options and the description of the given task.
				</p>
			</div>
			<div class="section">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title">
								<a name="sec:listing_dependencies"></a>11.6.4.&nbsp;获取依赖列表
							</h3>
							<h5 class="title">
                                <a name="sec:listing_dependencies"></a>11.6.4.&nbsp;Listing
                                project dependencies
                            </h5>
						</div>
					</div>
				</div>
				<p>
				    <a name="para:commandline_dependency_report"></a>执行 <strong
                        class="userinput"><code>gradle dependencies</code></strong>
                    会列出项目的依赖列表,所有依赖会根据任务区分,以树型结构展示出来.如下例.<br>
					<a name="para:commandline_dependency_report"></a>Running <strong
						class="userinput"><code>gradle dependencies</code></strong> gives
					you a list of the dependencies of the selected project, broken down
					by configuration. For each configuration, the direct and transitive
					dependencies of that configuration are shown in a tree. Below is an
					example of this report:
				</p>
				<div class="example">
					<a name="dependencyListReport"></a>
					<p class="title">
						<b>
						例&nbsp;11.13.&nbsp;获取依赖信息<br>
						Example&nbsp;11.13.&nbsp;Obtaining information about
							dependencies</b>
					</p>
					<div class="example-contents">
						<p>
							<strong class="userinput"><code>gradle
                                    -q dependencies api:dependencies webapp:dependencies</code></strong>
                                    的输出结果<br>
							Output of <strong class="userinput"><code>gradle
									-q dependencies api:dependencies webapp:dependencies</code></strong>
						</p>
						<pre class="screen">&gt; gradle -q dependencies api:dependencies webapp:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------

No configurations

------------------------------------------------------------
Project :api - The shared API for the application
------------------------------------------------------------

compile
\--- org.codehaus.groovy:groovy-all:2.3.3

testCompile
\--- junit:junit:4.11
     \--- org.hamcrest:hamcrest-core:1.3

------------------------------------------------------------
Project :webapp - The Web application implementation
------------------------------------------------------------

compile
+--- project :api
|    \--- org.codehaus.groovy:groovy-all:2.3.3
\--- commons-io:commons-io:1.2

testCompile
No dependencies</pre>
					</div>
				</div>
				<br class="example-break">
				<p>
	                   虽然输出结果很多,但这对于了解构建任务十分有用,当然你可以通过	<strong class="userinput"><code>--configuration</code></strong>参数来查看
	                   指定构建任务的依赖情况.<br>
   					Since a dependency report can get large, it can be useful to
					restrict the report to a particular configuration. This is achieved
					with the optional <strong class="userinput"><code>--configuration</code></strong>
					parameter:
				</p>
				<div class="example">
					<a name="dependencyListReportFiltered"></a>
					<p class="title">
						<b>
						例&nbsp;11.14.&nbsp;过滤依赖信息<br>
						Example&nbsp;11.14.&nbsp;Filtering dependency report by
							configuration</b>
					</p>
					<div class="example-contents">
						<p>
						 <strong class="userinput"><code>gradle
                                    -q api:dependencies --configuration testCompile</code></strong>的输出结果<br>
							Output of <strong class="userinput"><code>gradle
									-q api:dependencies --configuration testCompile</code></strong>
						</p>
						<pre class="screen">&gt; gradle -q api:dependencies --configuration testCompile
------------------------------------------------------------
Project :api - The shared API for the application
------------------------------------------------------------

testCompile
\--- junit:junit:4.11
     \--- org.hamcrest:hamcrest-core:1.3</pre>
					</div>
				</div>
				<br class="example-break">
			</div>
			<div class="section">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title">
								<a name="sec:dependency_insight"></a>11.6.5.&nbsp;查看特定依赖
							</h3>
							 <h5 class="title">
                                <a name="sec:dependency_insight"></a>11.6.5.&nbsp;Getting the
                                insight into a particular dependency
                            </h5>
						</div>
					</div>
				</div>
				<p>
				执行<a name="para:commandline_dependency_insight_report"></a>Running <strong
                        class="userinput"><code>gradle dependencyInsight</code></strong>
                        可以查看指定的依赖情况.如下例.<br>
					<a name="para:commandline_dependency_insight_report"></a>Running <strong
						class="userinput"><code>gradle dependencyInsight</code></strong>
					gives you an insight into a particular dependency (or dependencies)
					that match specified input. Below is an example of this report:
				</p>
				<div class="example">
					<a name="dependencyInsightReport"></a>
					<p class="title">
						<b>
						例&nbsp;11.15.&nbsp;获取特定依赖<br>
						Example&nbsp;11.15.&nbsp;Getting the insight into a
							particular dependency</b>
					</p>
					<div class="example-contents">
						<p>
						<strong class="userinput"><code>gradle
                                    -q webapp:dependencyInsight --dependency groovy --configuration
                                    compile</code></strong>的输出结果<br>
							Output of <strong class="userinput"><code>gradle
									-q webapp:dependencyInsight --dependency groovy --configuration
									compile</code></strong>
						</p>
						<pre class="screen">&gt; gradle -q webapp:dependencyInsight --dependency groovy --configuration compile
org.codehaus.groovy:groovy-all:2.3.3
\--- project :api
     \--- compile</pre>
					</div>
				</div>
				<br class="example-break">
				<p>
				这对于了解依赖关系、了解为何选择此版本作为依赖十分有用.了解更多请参阅 <a class="ulink"
                        href="../../dsl/org.gradle.api.tasks.diagnostics.DependencyInsightReportTask.html"
                        target="_top"><code class="classname">依赖检查报告</code></a>.<br>
					This task is extremely useful for investigating the dependency
					resolution, finding out where certain dependencies are coming from
					and why certain versions are selected. For more information please
					see <a class="ulink"
						href="../dsl/org.gradle.api.tasks.diagnostics.DependencyInsightReportTask.html"
						target="_top"><code class="classname">DependencyInsightReportTask</code></a>.
				</p>
				<p>
				    dependencyInsight任务是'Help'任务组中的一个.这项任务需要进行配置才可以.
				     如果用了Java相关的插件,那么dependencyInsight任务已经预先被配置到'Compile'下了.
				  你只需要通过'--dependency'参数来制定所需查看的依赖即可.如果你不想用默认配置的参数项你可以通过
				   '--configuration' 参数来进行指定.了解更多请参阅 <a class="ulink"
                        href="../../dsl/org.gradle.api.tasks.diagnostics.DependencyInsightReportTask.html"
                        target="_top"><code class="classname">依赖检查报告</code></a>.<br>
					The built-in dependencyInsight task is a part of the 'Help' tasks
					group. The task needs to configured with the dependency and the
					configuration. The report looks for the dependencies that match the
					specified dependency spec in the specified configuration. If java
					related plugin is applied, the dependencyInsight task is
					pre-configured with 'compile' configuration because typically it's
					the compile dependencies we are interested in. You should specify
					the dependency you are interested in via the command line
					'--dependency' option. If you don't like the defaults you may
					select the configuration via '--configuration' option. For more
					information see <a class="ulink"
						href="../dsl/org.gradle.api.tasks.diagnostics.DependencyInsightReportTask.html"
						target="_top"><code class="classname">DependencyInsightReportTask</code></a>.
				</p>
			</div>
			<div class="section">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title">
								<a name="sec:listing_properties"></a>11.6.6.&nbsp;获取项目属性列表
							</h3>
							<h5 class="title">
                                <a name="sec:listing_properties"></a>11.6.6.&nbsp;Listing
                                project properties
                            </h5>
						</div>
					</div>
				</div>
				<p>
				执行<strong class="userinput"><code>gradle properties</code></strong>可以获取项目所有属性列表.如下例.<br> 
					Running <strong class="userinput"><code>gradle
							properties</code></strong> gives you a list of the properties of the selected
					project. This is a snippet from the output:
				</p>
				<div class="example">
					<a name="propertyListReport"></a>
					<p class="title">
						<b>
						例&nbsp;11.16.&nbsp;属性信息<br>
						Example&nbsp;11.16.&nbsp;Information about properties</b>
					</p>
					<div class="example-contents">
						<p>
						<strong class="userinput"><code>gradle
                                    -q api:properties</code></strong>的输出结果<br>
							Output of <strong class="userinput"><code>gradle
									-q api:properties</code></strong>
						</p>
						<pre class="screen">&gt; gradle -q api:properties
------------------------------------------------------------
Project :api - The shared API for the application
------------------------------------------------------------

allprojects: [project ':api']
ant: org.gradle.api.internal.project.DefaultAntBuilder@12345
antBuilderFactory: org.gradle.api.internal.project.DefaultAntBuilderFactory@12345
artifacts: org.gradle.api.internal.artifacts.dsl.DefaultArtifactHandler@12345
asDynamicObject: org.gradle.api.internal.ExtensibleDynamicObject@12345
baseClassLoaderScope: org.gradle.api.internal.initialization.DefaultClassLoaderScope@12345
buildDir: /home/user/gradle/samples/userguide/tutorial/projectReports/api/build
buildFile: /home/user/gradle/samples/userguide/tutorial/projectReports/api/build.gradle</pre>
					</div>
				</div>
				<br class="example-break">
			</div>
			<div class="section">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title">
								<a name="sec:profiling_build"></a>11.6.7.&nbsp;构建日志
							</h3>
							<h5 class="title">
                                <a name="sec:profiling_build"></a>11.6.7.&nbsp;Profiling a build
                            </h5>
						</div>
					</div>
				</div>
				<p>
				<strong class="userinput"><code>--profile</code></strong>参数可以收集一些构建期间的信息并保存到
				<code class="filename">build/reports/profile</code>目录下并且以构建时间命名这些文件.<br>
					The <strong class="userinput"><code>--profile</code></strong>
					command line option will record some useful timing information
					while your build is running and write a report to the
					<code class="filename">build/reports/profile</code>
					directory. The report will be named using the time when the build
					was run.
				</p>
				<p>
				下面这份日志记录了总体花费时间以及各过程花费的时间.并以时间大小倒序排列.
				并且记录了任务的执行情况.<br>
				This report lists summary times and details for both the
					configuration phase and task execution. The times for configuration
					and task execution are sorted with the most expensive operations
					first. The task execution results also indicate if any tasks were
					skipped (and the reason) or if tasks that were not skipped did no
					work.</p>
				<p>
				    如果采用了buildSrc,那么在<code class="filename">buildSrc/build</code>下同时也会生成一份日志记录记录<br>
					Builds which utilize a buildSrc directory will generate a second
					profile report for buildSrc in the
					<code class="filename">buildSrc/build</code>
					directory.
				</p>
				<table cellpadding="0" cellspacing="0"
					summary="manufactured viewport for HTML img" border="0" width="903">
					<tr height="477">
						<td><img src="../img/profile.png" height="477"></td>
					</tr>
				</table>
			</div>
		</div>
		<div class="section">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title">
							<a name="sec:dry_run"></a>11.7.&nbsp;Dry Run
						</h2>
						<h4 class="title">
                            <a name="sec:dry_run"></a>11.7.&nbsp;Dry Run
                        </h4>
					</div>
				</div>
			</div>
			<p>
			     有时可能你只想知道某个任务在一个任务集中按顺序执行的结果,但并不想实际执行这些任务.那么你可以用<code class="option">-m</code>参数
			     例如<strong class="userinput"><code>gradle -m clean compile</code></strong>会调用<code class="literal">clean</code>
                                  和   <code class="literal">compile</code>,这与<code class="option">tasks</code>可以形成互补,让你知道哪些任务可以用于执行.<br>
				Sometimes you are interested in which tasks are executed in which
				order for a given set of tasks specified on the command line, but
				you don't want the tasks to be executed. You can use the
				<code class="option">-m</code>
				option for this. For example <strong class="userinput"><code>gradle
						-m clean compile</code></strong> shows you all tasks to be executed as part of the
				<code class="literal">clean</code>
				and
				<code class="literal">compile</code>
				tasks. This is complementary to the
				<code class="option">tasks</code>
				task, which shows you the tasks which are available for execution.
			</p>
		</div>
		<div class="section">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title">
							<a name="N10953"></a>11.8.&nbsp;本章小结
						</h2>
						<h4 class="title">
                            <a name="N10953"></a>11.8.&nbsp;Summary
                        </h4>
					</div>
				</div>
			</div>
			<p>
			在本章中你学到很多用命令行可以做的事情,了解更多你可以参阅<span
                    class="command"><strong>gradle</strong></span> command in <a
                    class="xref" href="gradle_command_line.html">附录&nbsp;D, <i>Gradle
                        命令行</i></a>.<br>
				In this chapter, you have seen some of the things you can do with
				Gradle from the command-line. You can find out more about the <span
					class="command"><strong>gradle</strong></span> command in <a
					class="xref" href="gradle_command_line.html">Appendix&nbsp;D, <i>Gradle
						Command Line</i></a>.
			</p>
		</div>
	</div>
	<div class="navfooter">
		<div>
			<div class="navbar">
				<a xmlns:xslthl="http://xslthl.sf.net"
					href="../ch10/web_project_tutorial.html"
					title="Chapter&nbsp;10.&nbsp;Web Application Quickstart">上一页</a><span>|</span><a
					xmlns:xslthl="http://xslthl.sf.net" href="../userguide.html"
					title="Gradle User Guide">返回目录</a><span>|</span><a
					xmlns:xslthl="http://xslthl.sf.net" href="../tutorial_gradle_gui.html"
					title="Chapter&nbsp;12.&nbsp;Using the Gradle Graphical User Interface">下一页</a>
			</div>
		</div>
	</div>
</body>
</html>